package cn.antia.cep.test;

import org.apache.commons.mail.HtmlEmail;

public class MailUtil {
	private String smtp;

	private String user;

	private String passwd;

	private boolean debug;

	public MailUtil(String smtp, String user, String passwd, boolean debug) {
		this.smtp = smtp;
		this.user = user;
		this.passwd = passwd;
		this.debug = debug;
	}

	public boolean sendHtml(String from,String to, String subject, String htmlContent) {
		try {
			HtmlEmail email = new HtmlEmail();
			email.setDebug(this.debug);
			email.setCharset("utf-8");
			email.setHostName(smtp);
			email.setAuthentication(user, passwd);
			// 内容
			email.addTo(to);
			email.setFrom(from);
			email.setSubject(subject);
			email.setHtmlMsg(htmlContent);
			
			email.send();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public static void main(String[] args) {
		String to="amy@2collegeboard.com";
		new MailUtil("smtp.2collegeboard.com", "admin@2collegeboard.com", "xb54062021",true).
		sendHtml("admin@2collegeboard.com",to, "zm，你好。", "text,a u fine.en...sleeping..sleeping..");
		System.out.println("finished...");
	}

}
